package com.lyb.springbootredisclient.app.sattagy;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.concurrent.atomic.AtomicReference;

/**
 * @author: lyb  2023/5/9 15:07
 */
@Service
public class StrategyServiceImpl implements StrategyService {
    @Autowired
    List<Strategy> strategyList;

    @Override
    public String payStrategy(String pay) {
        AtomicReference<String> v = new AtomicReference<>("请输入正确的支付方式");
        strategyList.forEach(strategy -> {
            Object object = strategy.getClass(pay);
            if (object instanceof PayService) {
                PayService payService = (PayService)object;
                v.set(payService.pay());
            }
        });
        System.out.println("lyb>>>>>>>1>>>>>>>>>>>>>>>"+v.get());
        return v.get();
    }
}
